package main

import (
	"fmt"
	//"github.com/google/uuid"
	"iot-base/common/dbconn"
	"iot-base/common/dbobj"
	//"math/rand"
	//"strings"
	//"time"
)

const id = "NzwlpRrDXSsliDtfYSqtw"

/*
,{"b":null,"box_id":null,"business_id":"","buy_time":null,"catalog_id":"公安",
"create_time":"2021-12-26T13:03:28.976506+08:00","creator":"",
"first_online_time":null,"id_in_box":null,"ip":"66.33.184.93","ipc_id":null,
"is_proxy":true,"is_station":false,"lat":"39.864251","level":0,"lon":"79.07719",
"maintain":"","model_id":"m_smartBoxForPolice","model_name":"智能监控箱",
"p":null,"parent_id":"X_CKLLLfIcewZ4H8bS_Tz","password":null,"play_addr":null,
"port":null,"protocol_path":"box","proxy_thing_id":"","rtsp":null,"s_name":"第三师图木舒克市锦绣街道金冠市场北门入口","sno":0,"state":0,"station_id":"NzwlpRrDXSsliDtfYSqtw","station_name":"三师","status_used":1,"thing_id":"NzwlpRrDXSsliDtfYSqtw","uid":"NzwlpRrDXSsliDtfYSqtw",
"used_time":"2021-12-26T13:03:28.976506+08:00","username":null}
*/
func main() {
	var sanshi dbobj.Thing
	err := dbconn.DBConnection.Where("uid=?", id).First(&sanshi).Error
	fmt.Println("find error-----------", err)
	if err == nil {
		// sanshi["model_id"] = "policeOffice"
		// sanshi["s_name"] = "三师"
		// sanshi["is_station"] = true
		// sanshi["protocol_path"] = ""
		// sanshi["proxy_thing_id"] = ""
		// sanshi["is_proxy"] = false
		sanshi.ModelID = "policeOffice"
		sanshi.SName = "三师"
		sanshi.IsStation = true
		sanshi.ProtocolPath = ""
		sanshi.ProxyThingID = ""
		sanshi.IsProxy = false
		sanshi.StatusUsed = 1

		err = dbconn.DBConnection.Save(&sanshi).Error
		fmt.Println("find save error-----------", err)

		var st dbobj.ThingStation
		err = dbconn.DBConnection.Where("thing_id=?", id).Delete(&st).Error
		fmt.Println("delete------------", err)

		err = dbconn.DBConnection.Where("thing_id=?", id).Delete(&dbobj.ThingParam{}).Error
		fmt.Println("delete-------2-----", err)
		err = dbconn.DBConnection.Where("param_id=? and param_value=?", "IP", "66.33.184.93").Delete(&dbobj.ThingParam{}).Error
		fmt.Println("delete-------2-----", err)
		var sanshisb dbobj.Thing
		sanshisb.ModelID = "m_smartBoxForPolice"
		sanshisb.IsProxy = true
		sanshisb.IsStation = false
		sanshisb.ProtocolPath = "box"
		sanshisb.StatusUsed = 1
		sanshisb.SName = "第三师图木舒克市锦绣街道金冠市场北门入口"
		sanshisb.Lon = "79.07719"
		sanshisb.Lat = "39.864251"
		sanshisb.AutoID()
		err = dbconn.DBConnection.Create(&sanshisb).Error
		fmt.Println("create--sanshisb----------", err)

		var sbstation dbobj.ThingStation
		sbstation.ThingID = sanshisb.UID
		sbstation.StationID = id
		err = dbconn.DBConnection.Create(&sbstation).Error
		fmt.Println("create--sbstation----------", err)

		var tp dbobj.ThingParam
		tp.ThingID = sanshisb.UID
		tp.ParamID = "IP"
		tp.ParamValue = "66.33.184.93"
		err = dbconn.DBConnection.Create(&tp).Error
		fmt.Println("save--tp----------", err)

	}

}
